package itypes

import (
	"server/game/model"
	"server/share/config"

	"github.com/hwcer/cosgo/uuid"
	"github.com/hwcer/logger"
	"github.com/hwcer/updater"
)

var Teams = teamsIType{}

func init() {
	Teams.IType = *NewIType(config.ITypeTeams)
	Teams.SetCreator(teamCreator)
	if err := updater.Register(updater.ParserTypeCollection, updater.RAMTypeAlways, &model.Teams{}, &Teams); err != nil {
		logger.Panic(err)
	}
}

func teamCreator(u *updater.Updater, iid int32, val int64) (any, error) {
	return model.NewTeams(u, iid, val), nil
}

type teamsIType struct {
	IType
}

func (t *teamsIType) UUID(uid string, iid int32) (r string, err error) {
	var u *uuid.UUID
	if u, err = model.UUID(uid); err == nil {
		r = u.New(uint64(iid)).String(uuid.BaseSize)
	}
	return
}
